package cn.edu.sjtu.spinning.dto;

import cn.edu.sjtu.spinning.domain.Task;
import cn.edu.sjtu.spinning.enums.DeviceStatus;
import cn.edu.sjtu.spinning.enums.TaskStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

import java.util.Date;

@Data
@Builder
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
/* 返回值，两个用处。首次查询状态时，返回ECN自身的状态，加入队列后，返回task的状态 用 有参数 和 无参数 来区分 */
public class StateResponse {
  private String taskId;
  private String processId;
  private Date time;
  private Integer status;
  private MockData data;
  private MockInfo info;

  public static StateResponse ofTaskState(Task task) {
    return StateResponse.builder()
        .taskId(task.getTaskId())
        .processId(task.getProcessId())
        .time(new Date())
        .status(task.getStatus().ordinal())
        .data(MockData.genRandomData())
        .info(MockInfo.genFixedInfo())
        .build();
  }

  public static StateResponse ofECNState(DeviceStatus state) {
    return StateResponse.builder().time(new Date()).status(state.ordinal()).build();
  }

  public static StateResponse ofTaskPendingState() {
    return StateResponse.builder().time(new Date()).status(TaskStatus.PENDING.ordinal()).build();
  }
}
